<template>
  <div>
    <Form ref="formValidate" :model="formValidate" :label-width="120" :label-colon="true" :rules="formRules"
          style="width: 200px;"
          :disabled="type === 3">
      <FormItem label="农村名称" prop="rfRuralName">
        <Input v-model="formValidate.rfRuralName"/>
      </FormItem>
      <FormItem label="服务中心照片">
        <Input v-model="formValidate.centerPhoto"/>
        <BaseUpload :disabled='type===3'
                    v-if="type!==3"
                    name = "file"
                    :showUploadList = "false"
                    btn-text = "上传服务中心照片"
                    @publicSuccess = "handleSuccess"
                    :action="action.upload"
        ></BaseUpload>
        <img :src=formValidate.centerPhoto style = "width: 140px ; height:140px" v-if="formValidate.centerPhoto" @click="openUploadFile">
      </FormItem>
      <FormItem label="集体照">
        <Input v-model="formValidate.groupPhoto"/>
      </FormItem>
      <FormItem label="党组织书记姓名">
        <Input v-model="formValidate.secretaryName"/>
      </FormItem>
      <FormItem label="党组织书记照片">
        <Input v-model="formValidate.secretaryPhoto"/>
      </FormItem>
      <FormItem label="党组织书记标签">
        <Input v-model="formValidate.secretaryTag"/>
      </FormItem>
      <FormItem label="党组织书记标签">
        <Input v-model="formValidate.secretaryHonor"/>
      </FormItem>
      <FormItem label="两委男班子数">
        <Input v-model="formValidate.committeeManNumber"/>
      </FormItem>
      <FormItem label="两委女班子数">
       <Input v-model="formValidate.committeeWomanNumber"/>
      </FormItem>
      <FormItem label="总人口数">
        <Input v-model="formValidate.populationNumber"/>
      </FormItem>
      <FormItem label="户数">
        <Input v-model="formValidate.householdsNumber"/>
      </FormItem>
      <FormItem label="常住人口数">
        <Input v-model="formValidate.residentsPopulationNumber"/>
      </FormItem>
      <FormItem label="户籍人口数">
        <Input v-model="formValidate.registeredPopulationNumber"/>
      </FormItem>
      <FormItem label="流动人口数">
        <Input v-model="formValidate.floatingPopulationNumber"/>
      </FormItem>
      <FormItem label="党员人数">
        <Input v-model="formValidate.partyMemberNumber"/>
      </FormItem>
      <FormItem :label-width="0" style="text-align: right">
        <Button style="margin-right: 10px;" @click="publicReset('formValidate')">取消</Button>
        <Button type="primary" @click="publicSubmit('formValidate')">确定</Button>
      </FormItem>
    </Form>
  </div>
</template>

<script>
import { updateMixin } from '@/mixin/index'
import API_KEY from '../../../api'
import store from '@/store'
import BaseUtil from '../../../utils/BaseUtil'

export default {
  mixins: [updateMixin],
  data () {
    return {
      formValidate: { // 搜索条件
        fkRuralId: store.getters.userInfo.deptList[0].id,
        rfRuralName: '',
        centerPhoto: '',
        groupPhoto: '',
        secretaryName: '',
        secretaryPhoto: '',
        secretaryHonor: '',
        secretaryTag: '',
        committeeNanNumber: 0,
        committeeWomanNumber: 0,
        populationNumber: 0,
        householdsNumber: 0,
        residentsPopulationNumber: 0,
        registeredPopulationNumber: 0,
        floatingPopulationNumber: 0,
        partyMemberNumber: 0
      },
      formRules: {
        rfRuralName: [{ required: true, message: '请输入农村名称', trigger: 'blur' }],
        centerPhoto: [{ required: true, message: '请输入服务中心图片', trigger: 'blur' }],
        secretaryName: [{ required: true, message: '请输入党组织书记姓名', trigger: 'blur' }],
        secretaryPhoto: [{ required: true, message: '请输入党组织书记照片', trigger: 'blur' }],
        secretaryHonor: [{ required: true, message: '请输入党组织书记荣誉', trigger: 'blur' }],
        secretaryTag: [{ required: true, message: '请输入党组织书记标签', trigger: 'blur' }],
        committeeManNumber: [{ required: true, message: '请输入两委男班子数', trigger: 'blur' }],
        committeeWomanNumber: [{ required: true, message: '请输入两委女班子数', trigger: 'blur' }],
        populationNumber: [{ required: true, message: '请输入总人口数', trigger: 'blur' }],
        householdsNumber: [{ required: true, message: '请输入户数', trigger: 'blur' }],
        residentsPopulationNumber: [{ required: true, message: '请输入常住人口', trigger: 'blur' }],
        registeredPopulationNumber: [{ required: true, message: '请输入户籍人口', trigger: 'blur' }],
        partyMemberNumber: [{ required: true, message: '请输入党员人数', trigger: 'blur' }]
      },
      action: {
        readDataById: API_KEY.ruralInfo.curdRural,
        createData: API_KEY.ruralInfo.createData,
        updateData: API_KEY.ruralInfo.update,
        upload: API_KEY.log.uploadFileLog
      }
    }
  },
  methods: {
    handleSuccess (data) {
      this.formValidate.centerPhoto = BaseUtil.getUploadPath(data.response.data.uploadPath)
      console.log(data)
    },
    openUploadFile () {
      const downPath = this.formValidate.centerPhoto
      window.open(downPath)
    }
  },
  components: {
    BaseUpload: () => import('@/components/view-ui/BaseUpload')
  }

}
</script>

<style scoped lang="scss">

</style>
